﻿Namespace ControlLibrary
    ''' <summary>
    ''' A special control to handle dates and times.
    ''' </summary>
    ''' <remarks>Used in the dbiWSFObjectDetail but can be used elsewhere if date/times are needed.</remarks>
    Public Class dbiDateTime
        Private l_DateTimeValue As Date

        ''' <summary>An event indicating that the date/time values have changed.</summary>
        Public Event DateValueChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        ''' <summary>A single date/time value comprised of the date picker and the time portion
        ''' of the control.</summary>
        Public Property DateTimeValue() As Date
            Get
                Return l_DateTimeValue
            End Get
            Set(ByVal value As Date)
                l_DateTimeValue = value
                dbiDDDate.Date = value
                dbiDDTime.Date = value
            End Set
        End Property

        ''' <summary>Instantiates a new dbiDateTime control.</summary>
        Public Sub New()
            ' This call is required by the Windows Form Designer.
            InitializeComponent()

            ' Add any initialization after the InitializeComponent() call.
            l_DateTimeValue = Now
            dbiDDDate.Date = Now
            dbiDDTime.Date = Now
        End Sub

        ''' <summary>
        ''' Instantiates a new dbiDateTime control.
        ''' </summary>
        ''' <param name="curDate">The current date/time to display in the two controls.</param>
        ''' <remarks></remarks>
        Public Sub New(ByVal curDate As Date)
            ' This call is required by the Windows Form Designer.
            Me.new()
            ' Add any initialization after the InitializeComponent() call.
            l_DateTimeValue = curDate
            dbiDDDate.Date = curDate
            dbiDDTime.Date = curDate

        End Sub
        ''' <summary>
        ''' Handles the date change in either of the dbi controls and raises and external event.
        ''' </summary>
        ''' <param name="sender">The object that changed.</param>
        ''' <param name="e">Generic system event args.</param>
        ''' <remarks></remarks>
        Private Sub dbiDDDate_DateChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dbiDDDate.DateChanged, dbiDDTime.DateChanged
            Try
                l_DateTimeValue = dbiDDDate.Date.Date.AddMilliseconds(dbiDDTime.Date.TimeOfDay.TotalMilliseconds)
            Catch ex As Exception
                l_DateTimeValue = Nothing
            End Try
            RaiseEvent DateValueChanged(sender, e)
        End Sub

    End Class

End Namespace